/*
 * Create in 2013-4-20 上午11:32:30.
 */
package kit4j.app.notepad.command;

import javax.swing.SwingUtilities;

import kit4j.app.notepad.service.ExceptionCatchService;
import kit4j.common.command.FullCommand;

/**
 * 
 * @author MiniKnife
 *
 */
public class DefaultNotepadCommandExecutor implements NotepadCommandExecutor {
	
	private static class RunnableCommand implements Runnable {
		
		private final FullCommand cmd;
		
		public RunnableCommand(FullCommand cmd) {
			this.cmd = cmd;
		}

		@Override
		public void run() {
			try {
				cmd.execute();
			} catch (Exception e) {
				ExceptionCatchService.getInstance().catchException(e);
			}
		}
	}

	/**
	 * @see kit4j.app.notepad.command.NotepadCommandExecutor#execute(kit4j.common.command.FullCommand)
	 */
	@Override
	public void execute(FullCommand cmd) {
		SwingUtilities.invokeLater(new RunnableCommand(cmd));
	}

	/**
	 * @see kit4j.app.notepad.command.NotepadCommandExecutor#undo(kit4j.common.command.FullCommand)
	 */
	@Override
	public void undo(FullCommand cmd) {
	}

	/**
	 * @see kit4j.app.notepad.command.NotepadCommandExecutor#redo(kit4j.common.command.FullCommand)
	 */
	@Override
	public void redo(FullCommand cmd) {
	}

}
